package com.zsrd.core.exception;

import cn.dev33.satoken.exception.NotLoginException;
import cn.dev33.satoken.exception.NotPermissionException;
import com.zsrd.core.response.BaseEnum;
import com.zsrd.core.response.ResponseSupport;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * <pre>
 *异常处理器
 * </pre>
 *
 * @author sunjiyong
 * @since 2023/12/13 8:20
 */
@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(NotLoginException.class)
    public ResponseSupport handleNotLoginException(NotLoginException e) {
        return ResponseSupport.of(BaseEnum.ResultEnum.NoToken.getCode()+"",BaseEnum.ResultEnum.NoToken.getName(),false);
    }

    @ExceptionHandler(NotPermissionException.class)
    public ResponseSupport handleNotPermissionException(NotPermissionException e) {
        return ResponseSupport.of(BaseEnum.ResultEnum.NoPermission.getCode()+"",BaseEnum.ResultEnum.NoPermission.getName(),false);
    }
}
